<template>
  <a-card :bordered="false">
    <!-- 查询区域 v-if="!projectInfo"-->
    <div class="table-page-search-wrapper" v-if="!projectInfo">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="4" :lg="7" :md="8" :sm="24" style="float: right;">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search" style="margin: 0 auto 10px">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin: 0 0 10px 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <div v-if="!!projectInfo" class="top-header">
      <h3>
        项目名称：{{ projectInfo.proName }}
        <span style="color: #999;font-size: 12px;">{{ projectInfo.proYear }}年</span>
      </h3>
      <a-row class="j-modal-title-row" type="flex">
        <a-col :span="12"> 项目区域：{{ projectInfo.areaId_dictText }} </a-col>
      </a-row>
      <a-row class="j-modal-title-row" type="flex">
        <a-col :span="12"> 涉及小区/村庄：{{ projectInfo.townNum }}个 </a-col>
        <a-col :span="12">
          <div style="float: right;">
            <a-upload
              name="file"
              :showUploadList="false"
              :multiple="false"
              :headers="tokenHeader"
              :action="importExcelUrl"
              @change="handleImportExcel"
            >
              <a-button type="primary" icon="import">导入村庄/小区</a-button>
            </a-upload>
            <span style="padding: 0 4px;"></span>
            <a-button type="primary" icon="download" @click="CustomHandleExportXls('项目村庄/小区导入模版')"
              >下载导入模板</a-button
            >
          </div>
        </a-col>
      </a-row>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> -->

      <!-- 高级查询区域 -->
      <!-- <j-super-query
        :fieldList="superFieldList"
        ref="superQueryModal"
        @handleSuperQuery="handleSuperQuery"
      ></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down"/></a-button>
      </a-dropdown> -->
    </div>

    <!-- table区域-begin -->
    <div>
      <!-- <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div> -->

      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
      >
        <!-- :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" -->
        <!-- @change="handleTableChange" -->
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text, record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            :preview="record.id"
            height="25px"
            alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
          <!-- <a @click="handleEdit(record)">编辑</a> -->
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>

    <project-town-detail-modal ref="modalForm" @ok="modalFormOk"></project-town-detail-modal>
  </a-card>
</template>

<script>
import Vue from 'vue'
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ProjectTownDetailModal from '../modules/projectTown/ProjectTownDetailModal'

export default {
  name: 'ProjectTownDetailList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    ProjectTownDetailModal
  },
  data() {
    return {
      description: '项目村庄明细表管理页面',
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: (t, r, index) => {
            const { pageSize, current } = this.ipagination
            return (current - 1) * pageSize + parseInt(index) + 1
          }
        },
        {
          title: '街道/乡镇',
          align: 'center',
          dataIndex: 'belongStreet_dictText'
        },
        {
          title: '小区/村',
          align: 'center',
          dataIndex: 'belongTown_dictText'
        },
        {
          title: '整改内容',
          align: 'center',
          dataIndex: 'contentLabel'
        }
        // {
        //   title: '操作',
        //   dataIndex: 'action',
        //   align: 'center',
        //   fixed: 'right',
        //   width: 147,
        //   scopedSlots: { customRender: 'action' }
        // }
      ],
      url: {
        list: '/paishui/projectTownDetail/list',
        delete: '/paishui/projectTownDetail/delete',
        deleteBatch: '/paishui/projectTownDetail/deleteBatch',
        exportXlsUrl: '/paishui/projectTownDetail/exportXls',
        importExcelUrl: 'paishui/projectTownDetail/importExcel'
      },
      disableMixinCreated: true,
      projectInfo: null,
      dictOptions: {},
      superFieldList: []
    }
  },
  created() {
    this.getSuperFieldList()
    this.initProjectInfo()
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    initProjectInfo() {
      const record = Vue.ls.get('ps_project_info')
      this.projectInfo = record || null
      console.log(record, 'record')
      if (record) {
        this.queryParam.belongProject = record.id
      }
      this.disableMixinCreated = false
      this.searchQuery()
    },
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'belongStreet', text: '所属街道', dictCode: '' })
      fieldList.push({ type: 'string', value: 'belongTown', text: '所属小镇', dictCode: '' })
      fieldList.push({ type: 'int', value: 'content', text: '整改内容', dictCode: '' })
      fieldList.push({ type: 'string', value: 'belongProject', text: '所属项目', dictCode: '' })
      this.superFieldList = fieldList
    },
    CustomHandleExportXls() {
      window.location.href =
        'https://zjhcsj.com/file/%E9%A1%B9%E7%9B%AE%E6%9D%91%E5%BA%84_%E5%B0%8F%E5%8C%BA%E5%AF%BC%E5%85%A5%E6%A8%A1%E7%89%88.xls'
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
